﻿<%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeBehind="email_sender.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Letter.email_sender" %>

<%@ Import Namespace="DataAccess" %>
<%@ Import Namespace="System.Net.Mail" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <% 
        string EmailContent = Request.Form["EmailContent"];
        EmailContent = HttpUtility.UrlDecode(EmailContent);
        string DateOfSend = Request.Form["DateOfSend"];
        string ClientEmail = Request.Form["ClientEmail"];
        string Email_ID = Request.Form["Email_ID"];
        string sender = Session["admin_id"].ToString();
        string Species = Request.Form["Species"];
        string senderID = "kilaxito@gmail.com";
        string pwd = "kiloxita@123";
        string reciever = ClientEmail;
        string subject = "Công Ty Cổ Phần Sen Quốc Tế xin chào quí khách!";
        string body = "<div style='padding:10px'><img src='http://www.tiengnhatthatde.com/content/img/logosqt.png' style='height:120px;width:120px' /><p style='color:grey;font-weight:bold;font-size:19px'>Xin chào!</p><br/>" + EmailContent + "<p style='color:black;font-weight:bold'>Sen Quốc Tế</p><p>Đây là email tự động, xin vui lòng không trả lời.</p></div>";
        SmtpClient smtpClient = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            Credentials = new System.Net.NetworkCredential(senderID, pwd),
            Timeout = 30000
        };
        MailMessage msg = new MailMessage(senderID, reciever, subject, body);
        msg.IsBodyHtml = true;
        smtpClient.Send(msg);

        string sended = sender + ";;" + DateOfSend + ";;" + EmailContent + ";;";

        if (Species == "1")
        {
            var emailColl = new TblContactController().FetchAll();
            var email = emailColl.Single(x => x.Id == Convert.ToInt32(Email_ID));
            new TblContactController().Update(email.Id, email.FullName, email.Birthday, email.Sex, email.Email, email.Phone, email.Address, email.Job, email.Traditional, email.Purpose, email.Degree, email.ClassX, email.Request, true, email.DateX, email.Sended + sended);
        }
        if (Species == "2")
        {
            var emailColl = new TblFeedbackController().FetchAll();
            var email = emailColl.Single(x => x.Id == Convert.ToInt32(Email_ID));
            new TblFeedbackController().Update(email.Id, email.FullName, email.Email, email.Phone, email.Problem, email.RpContent, true, email.Sended + sended);
        }
        if (Species == "3")
        {
            var emailColl = new TblCustomerEmailController().FetchAll();
            var email = emailColl.Single(x => x.Id == Convert.ToInt32(Email_ID));
            new TblCustomerEmailController().Update(email.Id, email.Email, email.Sended + sended);
        }
        //MailMessage msg = new MailMessage();

        //msg.From = new MailAddress("2neoplease@gmail.com");
        //msg.To.Add("binhan@senquocte.com");
        //msg.Body = "<div style='padding:10px'><img src='http://www.tiengnhatthatde.com/content/img/logosqt.png' style='height:120px;width:120px' /><p style='color:grey;font-weight:bold;font-size:19px'>Xin chào!</p>Mật khẩu mới của bạn là: <span style='font-weight:bold'>" + Capcha + "</span><br />Bạn có thể đăng nhập vào tài khoản của bạn <a href='http://www.tiengnhatthatde.com' style='color:#0d8567;font-weight:bold'>tại đây</a>.<p style='color:black;font-weight:bold'>Sen Quốc Tế</p><p>Đây là email tự động, xin vui lòng không trả lời.</p></div>";
        //msg.Subject = "[Sen Quốc Tế] Lấy lại mật khẩu tiengnhatthatde.com";
        //msg.IsBodyHtml = true;
        //SmtpClient smtp = new SmtpClient();
        //smtp.Host = "smtp.gmail.com";
        //System.Net.NetworkCredential Network = new System.Net.NetworkCredential();
        //Network.UserName = "2neoplease@gmail.com";
        //Network.Password = "saygoodbye";
        //smtp.UseDefaultCredentials = true;
        //smtp.Credentials = Network;
        //smtp.Port = 587;
        //smtp.EnableSsl = true;
        //smtp.Send(msg);
    %>
</body>
</html>
